package com.shop.service.impl;

import com.shop.mapper.IUserInfoMapper;
import com.shop.pojo.CommonResult;
import com.shop.pojo.UserAssembly;
import com.shop.pojo.UserVO;
import com.shop.service.IUserInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserInfoServiceImpl implements IUserInfoService {
    @Resource
    private IUserInfoMapper userInfoMapper;

    @Override
    public CommonResult<UserAssembly> getUsers(String query, int pageNum, int pageSize) {
        int offset = (pageNum - 1) * pageSize;
        List<UserVO> users = userInfoMapper.getUsers(query, offset, pageSize);
        UserAssembly userAssembly = new UserAssembly();
        userAssembly.setPageNum(pageNum);
        userAssembly.setTotal(getTotalUsers(query));
        userAssembly.setUserVO(users);
        return new CommonResult<>(200, "success", userAssembly);
    }

    @Override
    public int getTotalUsers(String query) {
        return userInfoMapper.getTotalUsers(query);
    }


}
